package com.xiaoa.controller;


import java.util.LinkedHashMap;


import com.xiaoa.annotation.JsonCache;
import com.xiaoa.base.Response;
import com.xiaoa.service.DomeService;
import com.xiaoa.sync.TestSyncIn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 
 * @author liang
 * @description controller测试
 */
@Controller
@RequestMapping("/activemq")
public class ActivemqController {
	
	
	@Autowired
	TestSyncIn sync ;
	
	@Autowired
	DomeService domeService;
	
	
	int num = 0;
	
	@ResponseBody
	@RequestMapping("testSync")
	public Response testSync(
			@RequestParam(value = "message" , required = true)String message,
			@RequestParam(value = "time" , required = true)Long time)throws Throwable{

		Response  response = new Response();
		
		response.setSucc(true);
		response.put("message", message);
		response.put("time", time);
		
		domeService.test(message, 2);
		
		return response;
	}
	
	@JsonCache(keyFieldName = "transactionKey" , filePath = "/aop/cache")
	@RequestMapping("testAop")
	@ResponseBody
	public Response testAop(
			@RequestParam(value = "message" , required = true)String message,
			@RequestParam(value = "transactionKey" , required = true)String transactionKey , 
			@RequestParam(value = "time" , required = true)Long time , 
			@RequestParam(value = "logMap" , required = false)LinkedHashMap<String, Object> logMap , 
			@RequestParam(value = "response" , required = false)Response response)throws Throwable{
		
		if (time == 366){
			throw new RuntimeException("错误 366");
		}
		
		response.setSucc(true);
		response.put("message", message);
		response.put("time", time);
		
		// 填充日志
		logMap.put("log_message", message);
		logMap.put("transactionKey", transactionKey);
		
		// 休眠
		System.out.println("========== 开始休眠 "  + time);
		Thread.sleep(time);
		System.out.println("========== 休眠结束 "  + time);
		
		return response;
	}
	
}
